using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
	[DataObject(true)]
    public partial class SubnetController
    {
	
		public SqlDataProvider DataProvider { get; set; }

        public SubnetController()
        {
            DataProvider = new SqlDataProvider();
        }
	
		[DataObjectMethod(DataObjectMethodType.Insert, true)]
        public Guid InsertSubnet(SubnetInfo oi)
		{
            return DataProvider.InsertSubnet(oi.ConfigurationId, oi.IP, oi.Mask, oi.StartIP, oi.EndIP, oi.StartInt, oi.EndInt);
		}

		[DataObjectMethod(DataObjectMethodType.Update, true)]
        public int UpdateSubnet(SubnetInfo oi) 
		{
			return DataProvider.UpdateSubnet(oi.SubnetId, oi.ConfigurationId, oi.IP, oi.Mask, oi.StartIP, oi.EndIP, oi.StartInt, oi.EndInt);
		}
		
		[DataObjectMethod(DataObjectMethodType.Delete, true)]
        public int DeleteSubnet(Guid subnetId)
		{
			return DataProvider.DeleteSubnet(subnetId);
        }

		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public SubnetInfo SelectSubnet(Guid subnetId)
        {    
			return ObjectFromDataRow(DataProvider.SelectSubnet(subnetId));
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<SubnetInfo> SelectSubnets()
		{
            return ListFromDataTable(DataProvider.SelectSubnets());
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<SubnetInfo> SelectSubnets(string sortExpression)
        {
            List<SubnetInfo> retList = SelectSubnets();
            if (sortExpression.Length > 0)
            {
                retList.Sort(new SubnetComparer(sortExpression));
            }
            return retList;
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<SubnetInfo> SelectSubnetsByConfiguration(Guid configurationId)
		{
			return ListFromDataTable(DataProvider.SelectSubnetsByConfiguration(configurationId));
		}
		
        public List<SubnetInfo> SelectSubnetsByConfiguration(Guid configurationId,string sortExpression)
		{
			List<SubnetInfo> retList = SelectSubnetsByConfiguration(configurationId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new SubnetComparer(sortExpression));
            }
            return retList;
		}

	}

}
		